using UnityEngine;
using QFramework;
using System.Linq;

namespace ProjectSurviver
{
	public partial class AbilityController : ViewController, IController
	{
        void Start()
		{
			Global.SimpleSwordUnlocked.RegisterWithInitValue(unlocked => // 注册事件，当SimpleSwordUnlocked的值发生变化时，执行以下代码
			{
				if(unlocked)
				{
					SimpleSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.SimpleKnifeUnlocked.RegisterWithInitValue(unlocked =>
			{
				if(unlocked)
				{
					SimpleKnife.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.RotateSwordUnlocked.RegisterWithInitValue(unlocked =>
			{
				if(unlocked)
				{
					RotateSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.BasketBallUnlocked.RegisterWithInitValue(unlocked =>
			{
				if(unlocked)
				{
					BasketballAbillity.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			// 随机升级一个道具
			this.GetSystem<ExpUpgradeSystem>().Items.Where(item => item.IsWeapon)
			.ToList()
			.GetRandomItem().Upgrade(); // 随机升级一个武器

			Global.SuperBoom.RegisterWithInitValue(unlocked =>
			{
				if(unlocked)
				{
					SuperBoom.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		public IArchitecture GetArchitecture()
        {
            return Global.Interface;
        }
	}
}
